public class Makehay {
    public static void main(String[] args) {
        int[] prices = new int[] {};
        int max = maxProfit(prices);
        System.out.println(max);
    }
    public static int maxProfit(int[] prices) {
        int xmax = 0;
        int xmin = 0;
        int max = prices[0];
        int min = prices[0];
        for (int i = 1; i < prices.length; i++) {
            if(prices[i] > max) {
                max = prices[i];
                xmax = i;
            }else if(prices[i] < min) {
                min = prices[i];
                xmin = i;
            }
        }
        if(xmax > xmin) {
            System.out.println(max+" "+min+" "+ xmax +" "+ xmin);
            return max - min;
        } else {
            int big = 0;
            for (int i = prices.length-1; i > 0; i--) {
                for (int j = 0; j < i; j++) {
                    if(prices[i] > prices[j]) {
                        if(prices[i]-prices[j] > big) {
                            big = prices[i]-prices[j];
                        }
                    }
                }
            }
            return big;
        }
    }
}
